<?php
   include ('mysql_connect.php');
   include ('func_list.php');

   // Подключаемся к mysql серверу
   $link = mysql_connect($dbhost, $dbuser, $dbpassword);
   if (empty($link)) {
      echo 'Не удалось подключиться к MySQL'; 
      exit;
   }
   // Выбираем нашу базу данных
   mysql_select_db($dbname, $link);
?>
</div>
<div style="float: right; width:24%;">
  <div class="sidebar">
    <div style="float:top;background-color:lightgrey;">
        <span style="color:blue;">Кнопки хороших сайтов</span>
    </div>
  </div>

  <div class="sidebar" align="center">
    <div style="float:top;background-color:lightgrey;" align="left">
        <span style="color:blue;">RSS</span>
    </div>
       
  </div>
  <div class="sidebar" align="center">
    <div style="float:top;background-color:lightgrey;" align="left">
        <span style="color:blue;">Свежие новости и статьи<br /> вам на почту:</span>
    </div>
<?php
if (isset($_GET['email'])) {
      $query = "INSERT INTO sub VALUES(0,'".$_GET['email']."');";
      $result = mysql_query($query, $link);
   }
?>
       <form action="" method="GET">
          <p>
          <input type="text" name="email" value="" /><br />
          <input type="submit" name="submit" value="Подписаться" />
          </p>
       </form>
  </div>

 <div class="sidebar">
    <div style="float:top;background-color:lightgrey;"><span style="color:blue;">Аккаунт</span>
    </div>
     <?php
        if ($state != 1) {
     ?>
     <form action="" method="POST">
     <p>
     <span>Логин: </span><input type="text" name="l_login" value="" /><br />
     <span>Пароль: </span><input type="password" name="l_pass" value="" /><br />
     <input type="submit" name="submit_login" value="Войти" />
     </p>
     </form>
     <a href="reg.php">Регистрация</a>
     <?php
        } else {
          echo '<p>Ваш логин: '.$userinfo["login"].'<br /><a href="?exit=y">Выход</a></p>';
        }
     ?>
   </div>
  <div class="sidebar">
    <div style="float:top;background-color:lightgrey;"><span style="color:blue;">Последние 5 комментариев</span>
    </div>
   <?php
      $query = "SELECT * FROM comments ORDER BY commentid DESC LIMIT 5";
      $result = mysql_query($query, $link);
      while ($line = mysql_fetch_row($result)) {
            echo '<div><p><div style="float:top;">';
            echo '<span style="color:blue;">'.$line[1].'</a><span style="font-size:70%;"> '.$line[5].' написал...</span>';
            echo '</span>';
            echo '</div>';
            echo '<span>'.comment_bbcode($line[2]).'</span></p>';
            echo '</div>';
      }
   ?>
  </div>
   <div class="sidebar">
   <div style="float:top; background-color:lightgrey;">
   <span style="color:blue;">Облако меток новостей</span>
   </div>
   <?php
   $tags_out = array();
   $str_out = '';
   $maximum = 0;
   $query = "SELECT * FROM mynews WHERE approved='1' ORDER BY id DESC";
   $result = mysql_query($query, $link);
   while ($line = mysql_fetch_array($result)) {
         $str_out .= trim($line["tags"]).',';
         $tags_out = explode(',', trim($str_out));
   }
   shuffle($tags_out);
   $tags_out = array_slice($tags_out,0,24);
   $tags = array_count_values($tags_out);
   $maximum = max($tags);
   echo '<div id="tagcloud">'."\n";
   foreach ($tags as $k => $value) {
       $percent = floor(($value / $maximum) * 100);
       if ($percent < 20) {
          $class = 'smallest';
       } elseif ($percent >= 20 and $percent < 40) {
          $class = 'small';
       } elseif ($percent >= 40 and $percent < 60) {
          $class = 'medium';
       } elseif ($percent >= 60 and $percent < 80) {
          $class = 'large';
       } else {
          $class = 'largest';
       }
       echo '<span class="'.$class.'"><a href="'.$_SERVER['PHP_SELF'].'?page=main&amp;tag='.urlencode($k).'" title="метка '.$k.'">'.$k.'</a></span>'."\n ";
   }
   echo '</div>';
      //Закрываем соединение
      mysql_close($link);
   ?>
   </div>
  <div class="sidebar">
    <div style="float:top;background-color:lightgrey;"><span style="color:blue;">Счётчики</span>
    </div>

  </div>
